package cate.game.farm.record;

import cate.game.play.proce.play.PlayPO;
import cate.game.role.Role;
import cate.game.role.base.RoleBase;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@NoteClass("单条通关记录")
public abstract class SinglePassRecord {

	@NoteField(value = "录像唯一id")
	public List<String> replayUids = new ArrayList<>();

	@NoteField(value = "玩家基础信息")
	public RoleBase roleBase;

	public final void tryRecord(Role role, List<PlayPO> plays) {
		if (isEmpty() || needUpdate(role, plays)) {
			recordBase(role,plays);
			doRecord(role, plays);
		}
	}

	//记录为空
	private boolean isEmpty() {
		return replayUids.isEmpty() || roleBase == null;
	}

	//是否需要更新
	protected abstract boolean needUpdate(Role role, List<PlayPO> plays);


	private void recordBase(Role role, List<PlayPO> plays){
		replayUids = plays.stream().map(a -> a.uid).collect(Collectors.toList());
		roleBase = role.getBase().copy();
	}

	protected abstract void doRecord(Role role, List<PlayPO> plays);


}
